package com.iran.Proxy.dynamicProxy;

import java.lang.reflect.InvocationTargetException;

/**
 * debug时会出现多次代理类地方法被执行，这是因为每次IDEA，或者其他编辑器获取代理类对象时，都尝试回去其方法
 */
public class MainTest {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        AManFactory aManFactory = new AManFactory();
        BWomanFactory bWomanFactory = new BWomanFactory();
        DiaoCompany diaoCompany = new DiaoCompany();
        diaoCompany.setFactory(aManFactory);
        /*Method[] declaredMethods = aManFactory.getClass().getDeclaredMethods();
        for (int i = 0; i < declaredMethods.length; i++) {
            if ("makeWomanToys".equals(declaredMethods[i].getName())){
                Method declaredMethod = declaredMethods[i];
                declaredMethod.invoke(aManFactory,"D");
            }
        }*/
        ManToyFactory proxyInstance = (ManToyFactory) diaoCompany.getProxyInstance();

        //Method[] declaredMethods = proxyInstance.getClass().getDeclaredMethods();

        proxyInstance.makeWomanToys("D");

        proxyInstance.makeFlyToy();

        diaoCompany.setFactory(bWomanFactory);
        WomanToyFactory proxyInstance1 = (WomanToyFactory) diaoCompany.getProxyInstance();
        proxyInstance1.makeManTools("181");
    }
}
